package service;

import data.*;
import java.awt.event.KeyEvent;

/**
 * 输入处理服务类
 */
public class InputService {
    // -------------------- service --------------------
    private GameRuntimeData runtimeData;
    private TankService tankService;

    public InputService() {
        this.runtimeData = GameRuntimeData.getInstance();
        this.tankService = new TankService();
    }

    /**
     * 功能: 处理键盘输入
     * W/↑ - 向上移动
     * A/← - 向左移动
     * S/↓ - 向下移动
     * D/→ - 向右移动
     * 空格 - 射击
     * 参数:
     *   keyCode: 按键代码
     * 返回值: void
     */
    public void handleKeyPressed(int keyCode) {
        if (runtimeData.getHero() == null || runtimeData.getHero().getState() != 1) return;

        switch (keyCode) {
            case KeyEvent.VK_W:
            case KeyEvent.VK_UP:
                tankService.moveTank(runtimeData.getHero(), 0);
                break;
            case KeyEvent.VK_D:
            case KeyEvent.VK_RIGHT:
                tankService.moveTank(runtimeData.getHero(), 1);
                break;
            case KeyEvent.VK_S:
            case KeyEvent.VK_DOWN:
                tankService.moveTank(runtimeData.getHero(), 2);
                break;
            case KeyEvent.VK_A:
            case KeyEvent.VK_LEFT:
                tankService.moveTank(runtimeData.getHero(), 3);
                break;
            case KeyEvent.VK_SPACE:
                tankService.tankShoot(runtimeData.getHero());
                break;
        }
    }
    // -------------------- service --------------------
}